package com.realife.ysuper.controller;

import com.realife.common.utils.R;
import com.realife.ysuper.entity.SkuEntity;
import com.realife.ysuper.service.SkuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;



/**
 * sku表,该表表示具体的商品实体,如黑色的 64g的iphone 8
 *
 * @author Albert
 * @email 15962463559@163.com
 * @date 2020-06-05 10:04:15
 */
@Slf4j
@RestController
@RequestMapping("/ysuper/sku")
public class SkuController {

    @Autowired
    private SkuService skuService;



    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("ysuper:sku:info")
    public R info(@PathVariable("id") Long id){
		SkuEntity sku = skuService.getById(id);

        return R.ok().put("sku", sku);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("ysuper:sku:save")
    public R save(@RequestBody SkuEntity sku){
		skuService.save(sku);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("ysuper:sku:update")
    public R update(@RequestBody SkuEntity sku){
		skuService.updateById(sku);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("ysuper:sku:delete")
    public R delete(@RequestBody Long[] ids){
		skuService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
